<?php if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' ); ?>
<table class="list userlist">
    <?php if ( empty( $infoData ) ) { ?>
    <tr class="empty">
        <td>您暂没有任何信息，<a href="<?php my_url('publish', 'rent'); ?>">去发布</a></td>
    </tr>
    <?php } else { ?>
    <?php
		$postIdArr = '';
		foreach($infoData as $single){
	?>
    <tr>
        <td class="i">
            <a href="<?php my_url('post', 'view', $single['id']); ?>" class="title"><?php echo $single['title']; ?></a>
            <strong><?php echo ( $single['type'] <= 2 ) ? '出租' : '出售'; ?></strong>
        </td>
        <td class="m"><?php echo number_format($single['amount'], 2); ?></td>
        <td class="h"><?php echo $single['roomname']; ?></td>
        <td class="t"><?php echo my_dateformat($single['updatetime']); ?>刷新</td>
        <td id="post_<?php echo $single['id']; ?>">
            <a href="<?php my_url('userinfo', 'refresh', $single['id']); ?>">刷新</a> / 
            <a href="<?php my_url('userinfo', 'edit', $single['id']); ?>">修改</a> / 
            <a href="<?php my_url('userinfo', 'delete', $single['id']); ?>" onclick="return window.confirm('确定要删除此信息么？');">删除</a>
        </td>
    </tr>
    <?php
			$postIdArr .= $single['id'] . ',';
		}
	?>
    <?php } ?>
</table>
<?php echo $pagination; ?>
<div class="c"></div>
</div>
<?php if( isset( $postIdArr ) ) { ?>
<script>
$(function(){
	//ajax获取信息未回复评论数
	var loadingImg = '<img src="<?php echo config_item('base_url') . 'image/loading.gif'; ?>" class="post_loading" />';
	var postids = '<?php echo trim($postIdArr, ','); ?>';
	$.ajax({
		type: 'POST',
		url: '<?php my_url('userinfo', 'ajaxGetCommentNum'); ?>',
		data: 'postids=' + postids,
		error: function(){
			alert('获取评论失败');
		},
		beforeSend: function(){
			var tmpArr = postids.split(',');
			for(var i=0;i<tmpArr.length;i++) {
				$('#post_' + tmpArr[i]).append( loadingImg );
			}
		},
		success: function(data){
			if ( data ) {
				data = eval('(' + data + ')');
				for(i=0;i<data.length;i++) {
					$('#post_' + data[i].id + ' .post_loading').remove();
					if( data[i].num > 0 ) {
						$('#post_' + data[i].id).append(' / <a href="<?php my_url('userinfo', 'comment', ''); ?>/' + data[i].id + '">' + data[i].num  + '评论</a>')
					}
				}
			}
		}
	});
});
</script>
<?php } ?>